// Package requests 处理请求数据和表单验证
package requests

import (
	"github.com/gofiber/fiber/v2"
	"github.com/thedevsaddam/govalidator"
)

type VehicleRequest struct {
	BrandId        uint64  `valid:"brand_id" json:"brand_id"`               //车辆品牌
	ModelId        uint64  `valid:"model_id" json:"model_id"`               //车辆型号
	Year           string  `valid:"year" json:"year" form:"year"`           //车辆出厂日期
	Color          string  `valid:"color" json:"color" form:"color"`        //颜色
	LicensePlate   string  `valid:"license_plate" json:"license_plate"`     //车牌号
	Mileage        float64 `valid:"mileage" json:"mileage"`                 //行驶公里数
	FuelId         uint64  `valid:"fuel_id" json:"fuel_id"`                 //燃油类型
	TransmissionId uint64  `valid:"transmission_id" json:"transmission_id"` //变速器类型
	EngineSize     float64 `valid:"engine_size" json:"engine_size"`         //发动机排量
	Seats          uint8   `valid:"seats" json:"seats"`
}

// https://pkg.go.dev/github.com/thedevsaddam/govalidator@v1.9.10#section-readme
func ValidateVehicle(c *fiber.Ctx, request *VehicleRequest) map[string][]string {
	c.BodyParser(request)
	rules := govalidator.MapData{
		"brand_id":        []string{"required"},
		"model_id":        []string{"required"},
		"year":            []string{"required", "datetime"},
		"color":           []string{"max_cn:10"},
		"license_plate":   []string{"required"},
		"fuel_id":         []string{"required"},
		"transmission_id": []string{"required"},
		"engine_size":     []string{"required"},
		"mileage":         []string{"required"},
		"seats":           []string{"required"},
	}

	messages := govalidator.MapData{
		// "name": []string{
		//     "required:名称为必填项",
		//     "min_cn:名称长度需至少 2 个字",
		//     "max_cn:名称长度不能超过 8 个字",
		// },
		// "description": []string{
		//     "min_cn:描述长度需至少 3 个字",
		//     "max_cn:描述长度不能超过 255 个字",
		// },
	}

	return Validate(request, rules, messages)
}
